﻿using Engine.Graphics;
using Engine;
using Game;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using T3j;

namespace T3j
{
    public class T3j : T3jBlock
    {

        public T3j()
            : base("Textures/common/weaponry/weapon_sword/sword_t3", 1f)
        {
        }


        public const int Index = 866;
    }
    public abstract class T3jBlock : Block
    {

        public T3jBlock(string textureName)
        {
            this.texture = textureName;
        }


        public T3jBlock(string textureName, float size)
        {
            this.texture = textureName;
            this.m_size = size;
        }


        public override void Initialize()
        {
            base.Initialize();
            Model model = ContentManager.Get<Model>("Models/common/weaponry/weapon_sword/sword_t3", null);
            Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Handle", true).ParentBone);
            Matrix boneAbsoluteTransform2 = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Head", true).ParentBone);
            this.m_standaloneBlockMesh.AppendModelMeshPart(model.FindMesh("Handle", true).MeshParts[0], boneAbsoluteTransform * Matrix.CreateTranslation(0f, -0.2f, 0f) * Matrix.CreateRotationX(1.59f), false, false, true, false, Color.White);
            this.m_standaloneBlockMesh.AppendModelMeshPart(model.FindMesh("Head", true).MeshParts[0], boneAbsoluteTransform * Matrix.CreateTranslation(0f, -0.2f, 0f) * Matrix.CreateRotationX(1.59f), false, false, true, false, Color.White);
            this.m_texture = ContentManager.Get<Texture2D>(this.texture, null);
        }


        public override void GenerateTerrainVertices(BlockGeometryGenerator generator, TerrainGeometry geometry, int value, int x, int y, int z)
        {
        }


        public override void DrawBlock(PrimitivesRenderer3D primitivesRenderer, int value, Color color, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData)
        {
            BlocksManager.DrawMeshBlock(primitivesRenderer, this.m_standaloneBlockMesh, this.m_texture, color, this.m_size * size, ref matrix, environmentData);
        }


        private Texture2D m_texture;


        private BlockMesh m_standaloneBlockMesh = new BlockMesh();


        private string texture;

        private float m_size = 1f;
    }

   





}
